function handleOrder(oldOrderData, dataMap, currentTime, styleCodeList, styleIngredient, style, category, timeArr) {

    function formatDate(date) {
        //console.log("date", date, typeof date)
        if (typeof date == "undefined") {
            return null
        }
        if (typeof date == "string") {
            date = new Date(date)
        }
        return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`
    }

    let timeMap = timeArr.reduce((pre, next) => { pre[next.数据ID] = next; return pre }, {})

    function findParentCategory(currentCategoryId) {
        let timeObj = timeArr.find(i => i.数据ID === currentCategoryId)
        if (timeObj) {
            return { result: timeObj }
        }
        let parentId = (category.find(i => i.数据ID === currentCategoryId) || {}).parentId
        if (parentId) {
            return findParentCategory(parentId)
        }
        return { result: null }
    }

    let currentDate = new Date()
    let nextDate = new Date(Date.now() + 86400000 * 10)
    let planStartDate = formatDate(currentDate)
    let planEndDate = formatDate(nextDate)

    let order = {}
    let detail
    order.oldCode = oldOrderData.合同编号
    switch (oldOrderData.订单类型) {
        case "定制大货": order.orderType = 1;
            break;
        case "定制补货": order.orderType = 2;
            break;
        case "高级定制": order.orderType = 1;
            break;
        case "专卖单": order.orderType = 4;
            break;
        default: order.orderType = 1;
            break;
    }
    let styleIngredientMap = {}
    for (let j = 0; j < styleCodeList.length; j++) {
        let styleId = styleCodeList[j].styleId
        styleIngredientMap[styleId] = styleIngredient.filter(i => i.styleId === styleId).map(i => i.code)
    }

    let payTypeMap = {
        "立即付款，到期净值": "0001",
        "全额预付": "Z001",
        "未到货未到票预付10%订金，出货前预付90%提货": "Z002",
        "未到货未到票预付20%订金，出货前预付80%提货": "Z003",
        "未到货未到票预付30%订金，出货前预付70%提货": "Z004",
        "未到货未到票预付30%订金，出货前预付60%提货，货到票到后付10%": "Z005",
        "未到货未到票预付20%订金，出货前预付70%提货，货到票到后付10%": "Z006",
        "未到货未到票预付90%订金，货到票到后付10%": "Z007",
        "每月到货入库物料总金额，票到后于次月固定时间一起结算": "Z008",
        "每月到货入库物料总金额，于次月固定时间一起结算（票未到）": "Z009",
        "每月到货入库物料总金额，票到后于次次月固定时间一起结算": "Z010",
        "每季到货入库物料总金额，票到后于下个季度第一个月固定时间一起结算": "Z011",
        "未到货未到票预付50%，到货到发票后付清50%": "Z012",
        "现金结算": "Z013",
        "生产前预付30%，提货时全部结清": "Z020"
    }
    let settleOrgMap = {
        "浙江乔治白服饰股份有限公司": "100",
        "河南乔治白服饰有限公司": "210",
        "云南乔治白服饰股份有限公司": "220",
        "上海乔治白实业有限公司": "500",
        "温州乔治白贸易有限公司": "600",
        "温州乔治白网络科技销售组织": "700"
    }
    order.updateTime = currentTime
    order.auditTime = currentTime
    order.clerk = oldOrderData.业务员
    order.step = "完整订单"
    order.payType = payTypeMap[oldOrderData.付款方式] || null
    // order.distributior = oldOrderData.隶属
    order.settleOrg = settleOrgMap[oldOrderData.卖方] || null
    order.businessAgent = oldOrderData.商务代表
    order.settleCustomerCode = oldOrderData.买方
    order.usedCustomerCode = oldOrderData.最终客户编号
    order.distributiorCode = oldOrderData.隶属
    let productDescription = oldOrderData.备注 + oldOrderData.交货地点 + oldOrderData.其他约定 + oldOrderData.备注 + oldOrderData.备忘 + oldOrderData.包装物标识 + oldOrderData.洗水唛厂名

    let personalMeasureBody = dataMap.量体数据头.filter(i => i.订单号 === order.oldCode)
    personalMeasureBody.forEach(item => {
        item.emploeeId = item.工号
        item.sex = item.性别 === "男" ? 1 : 0
        item.approveStatus = 1
        item.measureStatus = 2
    })

    let orderAfterMeasureBodyDetail = dataMap.订单明细表.filter(i => i.HTBN === order.oldCode)
    // 生成materialList
    for (let j = 0; j < orderAfterMeasureBodyDetail.length; j++) {
        let currentDetail = orderAfterMeasureBodyDetail[j]

        let newStyle = styleCodeList.find(i => i.OldStyleCode === currentDetail.成品货号)
        if (!newStyle) {
            return { reason: `${currentDetail.成品货号}没有对应的新款式` }
        }
        if (newStyle.styleOrigin === "style" && styleIngredient.some(i => !i.amount && i.styleId === newStyle.styleId)) {
            return { reason: `stlyeId为${newStyle.styleId}的款式的${styleIngredient.find(i => i.styleId === newStyle.styleId && !i.amount).code}物料是0` }
        }
        let currentStyle = style.find(i => i.数据ID === newStyle.styleId)
        if (!currentStyle) {
            //console.log("style", style)
            //console.log("newStyle.styleId", newStyle.styleId)
            return { reason: `${newStyle.styleId}没有款式信息` }
        }
        currentDetail.categoryId = currentStyle.categoryId
        currentDetail.styleId = newStyle.styleId
        currentDetail.styleOrigin = newStyle.styleOrigin
        currentDetail.styleCode = newStyle.NewStyleCode
        currentDetail.materialAvailablePlanDate = formatDate(currentDetail.面料预计到货时间)
        /*let materialList = dataMap.辅料配料.filter(sub => sub.订单子明细ID === currentDetail.明细ID).map(i => {
                      let amount = i.用量 - 0
                      let styleIngredientAmount = i.用量 - 0
                      let unit = i.单位名称
                      let name = i.辅料类别
                      let code = i.货号.replaceAll(".","")
                      let productNum = (currentDetail.数量 - 0) || 0
                      if (unit === "M") {
                        unit = "米"
                      }
                      return {amount, styleIngredientAmount, unit, name, code, productNum}
                    })*/
        /*let emptyCode = styleIngredientMap[currentDetail.styleId].find(i => !materialList.some(sub => sub.code === i))
                    if (emptyCode) {
                      return {reason: `${emptyCode}裁片物料在旧frp导入物料中不存在`}
                    }*/
        currentDetail.cacheMaterialList = []//materialList
    }

    let productionOrder = dataMap.批号表.filter(i => i.订单ID === order.oldCode && !i.生产类别.includes("售后"))

    let personalMeasureBodyStyle = dataMap.量体数据明细.filter(i => personalMeasureBody.some(sub => sub.Djlsh === i.ParentDjlsh))
    personalMeasureBodyStyle.forEach(item => {
        // console.log("item.量体指标组", item.量体指标组)
        if (item.量体指标组) {
            let changeArr = item.量体指标组.split("|").concat(item.备注).filter(i => i)
            if (changeArr.length) {
                item.change = changeArr.join(",")
            }
        }

        item.standard = item.规格
        item.size = item.号型
        item.importSentinal = item.订单明细ID
        item.number = item.tx17 - 0
    })

    let typeMap = {
        高级订制: 1,
        投标样衣: 2,
        量体样衣: 3,
        技术样衣: 4,
        普通样衣: 5,
        普通大货: 6
    }
    let date = oldOrderData.交货日期

    let deliveryDate = formatDate(date)
    orderAfterMeasureBodyDetail.forEach(item => {
        item.materialAvailableDate = formatDate(item.面料预计到货时间) || planStartDate
        item.itemNum = item.数量 - 0
        item.planEndDate = planEndDate
        item.planStartDate = planStartDate
        item.deliveryDate = deliveryDate
        /*item.type = typeMap[item.样衣类型]
                    if (!item.type) {
                      if (oldOrderData.样衣类型 && oldOrderData.样衣类型.includes("样衣")) {
                        item.type = 5
                      } else {
                        item.type = 6
                      }
                    }*/
        let deliverTypeMap = { 自制: 1, 委外: 3, 外购: 5 }
        item.type = 6
        if (oldOrderData.订单类型 === "高级定制") {
            item.type = 1
        }
        item.deliverType = deliverTypeMap[item.生产类型]
        item.oldMaterialCode = item.成品货号
        item.description = item.要求
        item.deliverType = 1
        item.clientPrice = item.开票单价 * 100
        item.price = item.单价 * 100
        item.styleOrigin = "style"
        item.productDescription = productDescription
        personalMeasureBodyStyle.filter(i => i.订单明细ID === item.明细ID).forEach(i => {
            i.styleId = item.styleId
            i.styleOrigin = item.styleOrigin
            i.styleCode = item.styleCode
        })
        switch (item.计划生产基地) {
            case "浙江": item.dept_id = 5793382;
                break;
            case "河南": item.dept_id = 673535316;
                break;
            case "云南": item.dept_id = 673488468;
                break;
            default: break;
        }
    })

    productionOrder.forEach(item => {
        let detail = orderAfterMeasureBodyDetail.find(i => item.订单明细ID === i.明细ID)
        let categoryId = detail.categoryId
        item.deliverType = detail.deliverType
        item.materialAvailablePlanDate = detail.materialAvailablePlanDate
        item.oldCode = item.批号
        item.totalNum = item.件数 - 0
        item.styleOrigin = "style"
        date = item.预计开工期
        item.planStartDate = planStartDate
        item.planEndDate = planEndDate
        if (item.deliverType === 5) {
            item.status = 1
        }
        /*if (date && typeof date === "object") {
                      //console.log("date1", date)
                      item.planStartDate = formatDate(date)
                    }*/
        item.报工 = dataMap.报工.filter(i => i.生产批号 === item.oldCode && i.完成数量 > 0)
        item.报工.forEach(e => {
            e.startDate = formatDate(e.创建时间)
            e.planStartDate = e.startDate
            e.sendNum = 0
            e.reportNum = e.完成数量 - 0
            e.currentStepNum = e.reportNum
            e.sectionType = e.操作类型
            e.dept_id = item[e.sectionType + "车间"]
            e.status = 2
            if (e.完成数量 === item.totalNum) {
                e.endDate = formatDate(e.操作日期)
                e.planEndDate = e.endDate
                e.status = 1
            }
        })

        debugger
        if (item.deliverType === 1) {
            let scheduleDetail = JSON.parse(JSON.stringify(item.报工))
            let sectionTypeArr = ["裁剪", "缝制", "后整理"]
            for (let k = 0; k < sectionTypeArr.length; k++) {
                let currentSectionType = sectionTypeArr[k]
                let createTime = item[currentSectionType + "开工"] || item[currentSectionType + "开始"]
                if (!item.报工.some(i => i.sectionType === currentSectionType)) {
                    let obj = {
                        创建时间: createTime,
                        planStartDate: formatDate(createTime),
                        status: 0,
                        dept_id: item[currentSectionType + "车间"],
                        sendNum: 0,
                        reportNum: currentSectionType === "裁剪" ? item.totalNum : 0,
                        sectionType: currentSectionType,
                        currentStepNum: currentSectionType === "裁剪" ? item.totalNum : 0
                    }
                    if (currentSectionType === "裁剪") {
                        item.报工.push(obj)
                    }
                    scheduleDetail.push(obj)
                }
            }
            item.scheduleDetail = scheduleDetail
            item.departmentData = scheduleDetail
            item.planDateData = scheduleDetail
            if (scheduleDetail.find(i => i.sectionType === "后整理").status !== 1) {
                item.scheduleStatus = 2
            }
            // window.console.log("scheduleDetail", scheduleDetail)
        }
    })

    if (!productionOrder || !productionOrder.length) {
        productionOrder = orderAfterMeasureBodyDetail.map(i => {
            i.订单明细ID = i.明细ID
            i.totalNum = i.itemNum
            return i
        })
    }

    productionOrder.forEach(item => {
        const stockIn = item['报工'].find(item => item['操作类型'] === '入库') || {}
        if (parseInt(stockIn['完成数量']) === item.totalNum) {
            item.status = 1
        } else {
            item.status = 2
        }
        item.scheduleStatus = item.scheduleStatus || 1
    })

    const auxiliaryMaterial = []
    for (const item of orderAfterMeasureBodyDetail) {
        auxiliaryMaterial.push(...dataMap.辅料配料.filter(i => i.订单子明细ID === item.明细ID))
    }
    order.auxiliaryMaterial = auxiliaryMaterial

    order.orderAfterMeasureBodyDetail = orderAfterMeasureBodyDetail
    order.personalMeasureBody = personalMeasureBody
    order.personalMeasureBodyStyle = personalMeasureBodyStyle
    order.productionOrder = productionOrder

    return { result: order }
}